/**
 * Created by jiangtao on 2017/5/24.
 */

import React , { Component , PropTypes } from 'react';

// import  {PropTypes} from 'prop-types';

import {
    Route,
    Link,
} from 'react-router-dom';

export default class CustomLink extends Component {
    constructor( props ){
        super(props);
    }

    static defaultProps = {
        to:'/',
        activeOnlyWhenExact:true,
        className:"custom"
    };

    render(){
        const {
            to,
            children,
            className,
            activeOnlyWhenExact
        } = this.props;
        return (
            <Route path={to} exact={activeOnlyWhenExact} children={({ match }) => {
                const clasName =  className + ( match ? ' active' : '' );
                return match ?
                    <a className={clasName}>
                        {children}
                    </a> :
                    <Link to={to} className={clasName}>
                        {children}
                    </Link>
            }}/>
        )
    }
};
